package com.ajk.server.bkcontroller;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ajk.server.model.BodypartDict;
import com.ajk.server.model.query.BodypartDictQuery;
import com.ajk.server.model.response.BodypartDictRes;
import com.ajk.server.model.response.Result;
import com.ajk.server.model.response.ResultList;
import com.ajk.server.model.response.ResultObject;
import com.ajk.server.service.BodypartDictService;

/**
 * 疾病相关接口
 * @author chenxuan
 * 
 * t_disease
 * dict_bodypart
 * r_disease_bodypart
 */
@Controller
@RequestMapping(value="/admin/bodypart")
public class AdminBodyPartController {
	
	Logger logger = LoggerFactory.getLogger(AdminBodyPartController.class);

	@Autowired
	private BodypartDictService bodypartDictService;
	
	/**
	 * 身体部位管理-身体部位列表
	 * 
	 * @return
	 */
	@RequestMapping(value="/list",method=RequestMethod.GET)
	@ResponseBody
	public ResultList<BodypartDictRes> getBodypartDictList(BodypartDictQuery query){
		long start = System.currentTimeMillis();
		ResultList<BodypartDictRes> list = new ResultList<BodypartDictRes>();
		
		List<BodypartDictRes> result = bodypartDictService.findBodypartDictByQuery(query);
		Integer count = bodypartDictService.countBodypartDictByQuery(query);
		query.setCount(count);
		list.setExt(query);
		list.setItemList(result);
		System.err.println("=============Cost:"+(System.currentTimeMillis()-start));
		return list;
	}
	
	@RequestMapping(value="/list/{parentId}",method=RequestMethod.GET)
	@ResponseBody
	public ResultList<BodypartDictRes> getBodypartDictByParentList(@PathVariable("parentId") Integer parentId){
		ResultList<BodypartDictRes> list = new ResultList<BodypartDictRes>();
		List<BodypartDictRes> result = bodypartDictService.findByParentId(parentId);
		list.setItemList(result);
		return list;
	}
	
	/**
	 * 身体部位管理-添加身体部位
	 */
	@RequestMapping(value="/add",method=RequestMethod.POST)
	@ResponseBody
	public ResultObject<Integer> addBodyPart(@RequestBody BodypartDict dict){
		
		Integer id = bodypartDictService.insertBodypartDict(dict);
		
		return new ResultObject<>(id);
	
	}
	
	
	/**
	 * 身体部位管理-修改身体部位
	 */
	@RequestMapping(value="/modify",method=RequestMethod.PUT)
	@ResponseBody
	public ResultObject<Integer> modifyBodyPart(@RequestBody BodypartDict dict){
		
		Integer id = bodypartDictService.updateBodypartDict(dict);
		
		return new ResultObject<>(id);
	
	}
	
	/**
	 * 身体部位管理-删除身体部位
	 */
	@RequestMapping(value="/delete/{id}",method=RequestMethod.DELETE)
	@ResponseBody
	public Result deleteBodyPart(@PathVariable("id") Integer id){
		bodypartDictService.deleteBodypartDictById(id);
		return new Result();
	}
	
}